package com.whcoding.task.xxl.job.task.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadSettingUtils {
    public static ThreadPoolExecutor getSingleThreadExecutor(String nameFormat) {
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat(nameFormat).build();

        return new ThreadPoolExecutor(1, 1,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(), namedThreadFactory);
    }

    public static void sleep(long ms){
        try {
            TimeUnit.MILLISECONDS.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
